<template>
  <div class="search-container">搜索页面
    <form action="/">
      <van-search
         v-model="searchText"
         show-action
         placeholder="请输入搜索关键词"
         background="#3296fa"
         @search="onSearch"
         @cancel="onCancel"
         @focus="isResultShow = false"
      />
    </form>
    <!-- 搜索结果 -->
    <search-result v-if="isResultShow" />
    <!-- 联想建议 -->
    <search-suggestion v-else-if="searchText" :search-text="searchText" />
    <!-- 搜索历史记录 -->
    <search-history v-else />
  </div>
</template>

<script>
import searchHistory from './components/search-history.vue'
import searchSuggestion from './components/search-suggestion.vue'
import searchResult from './components/search-result.vue'
export default {
  name: 'SearchIndex',
  components: {
      searchHistory,
      searchSuggestion,
      searchResult
  },
  data() {
    return {
      searchText: '',
      isResultShow: false // 控制搜索结果的显示状态
    }
  },
  methods: {
    onSearch(val) {
     console.log(val)
     this.isResultShow = true
    },
    onCancel() {
      this.$router.back()
    }
  }
}
</script>

<style scoped lang="less">
.search-container {
     .van-search__action {
       color: #fff;
     }
   }
</style>